// File GenericPerson.cpp
//
// Purpose: Class defining a generic person interacted with along
//	the ship
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 21 March 2013
// --------------------------------------------------------------
#define DEBUG_SECTION

#include "GenericPerson.h"

#include <string>
#include <cassert>
#include <iostream>

#include "EntityNames.h"
#include "BaseGameEntity.h"
#include "LocationMachine.h"
#include "Locations.h"
#include "misc/ConsoleUtils.h"
#include "GenericPersonStates.h"
#include "StateMachine.h"
#include "IPerson.h"
#include "Item.h"

CGenericPerson::CGenericPerson(int id, CLocation* locationOfPerson) : CBaseGameEntity(id), 
	IPerson(), m_iHealth(MaxHealthLevelForGenericPerson)
{
	//set up state machine
	m_pStateMachine = new CStateMachine<CGenericPerson>(this);
	m_pLocationMachine = new CLocationMachine(this);
	m_pStateMachine->SetCurrentState(Standby::Instance());
	m_pLocationMachine->SetCurrentLocation(locationOfPerson);
}

CGenericPerson::~CGenericPerson(){delete m_pStateMachine;}

bool CGenericPerson::HandleMessage(const Telegram& msg)
{
	return m_pStateMachine->HandleMessage(msg);
}

void CGenericPerson::Update()
{
	SetTextColor(FOREGROUND_BLUE| FOREGROUND_INTENSITY);
	m_pStateMachine->Update();
	m_pLocationMachine->Update();
}

void CGenericPerson::CheckInventory()
{
	// Output inventory to console
	SetTextColor(BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
	
	cout << endl;
	cout << "Your inventory contains the following:" << endl;
	cout << endl;
	cout << m_oInventory.ListItems();
	cout << endl;
}

CStateMachine<CGenericPerson>* CGenericPerson::GetFSM() const 
{
	return m_pStateMachine;
}

CLocationMachine* CGenericPerson::GetLocationMachine() const 
{
	return m_pLocationMachine;
}

std::string CGenericPerson::Name() const
{
	return GetNameOfEntity(this->ID());
}

int CGenericPerson::GetID() const 
{
	return this->ID();
}

//-------------------------------------------------------------accessors
void CGenericPerson::SetHealth(int val)
{
	m_iHealth = val;
}
int CGenericPerson::Health() const
{
	return m_iHealth;
}
